//
//  TPOffsetScreenRenderController.m
//  TEXT
//
//  Created by liubo on 2023/10/15.
//  Copyright © 2023 刘博. All rights reserved.
//

#import "TPOffsetScreenRenderController.h"

@interface TPOffsetScreenRenderController ()

@end

@implementation TPOffsetScreenRenderController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
   // [self testMask];
  //  [self testVisiual];
   // [self testBezierPath];
   // [self testCoreGraphics];
  //  [self testRasterize];
    [self testGroupopacity];
    // Do any additional setup after loading the view.
}

- (void)testCorner
{
    CGSize roundedViewSize = CGSizeMake(200.0, 200.0);
       UIView * roundedView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - roundedViewSize.width) / 2, (self.view.frame.size.height - roundedViewSize.height) / 2, roundedViewSize.width, roundedViewSize.height)];
       // 设置圆角
       roundedView.layer.cornerRadius = roundedViewSize.width / 2.0;
       // 设置边框 - 没有影响
   //    roundedView.layer.borderWidth = 2.0;
   //    roundedView.layer.borderColor = UIColor.redColor.CGColor;
       // 设置裁剪
       roundedView.clipsToBounds = YES;
       
       [self.view addSubview:roundedView];
       
       // 设置内容
       roundedView.backgroundColor = UIColor.greenColor;
    CGSize subViewSize = CGSizeMake(200.0, 200.0);
        CALayer * subLayer = [[CALayer alloc] init];
        subLayer.frame = CGRectMake((roundedView.frame.size.width - subViewSize.width) / 2, (roundedView.frame.size.height - subViewSize.height) / 2, subViewSize.width, subViewSize.height);
        subLayer.backgroundColor = UIColor.blueColor.CGColor;
       // [roundedView.layer addSublayer:subLayer];
//    roundedView.layer.backgroundColor = [UIColor redColor].CGColor;
//       roundedView.layer.contents = (__bridge id)[UIImage imageNamed:@"hhh"].CGImage;
       
    
    UIView * subView = [[UIView alloc] initWithFrame:CGRectMake((roundedView.frame.size.width - subViewSize.width) / 2, (roundedView.frame.size.height - subViewSize.height) / 2, subViewSize.width, subViewSize.height)];
       subView.backgroundColor = UIColor.purpleColor;
       [roundedView addSubview:subView];

}

- (void)testMask
{
    CGSize viewSize = CGSizeMake(200.0, 200.0);
       UIView * testView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - viewSize.width) / 2, (self.view.frame.size.height - viewSize.height) / 2, viewSize.width, viewSize.height)];
       
       // 设置内容
   //    testView.backgroundColor = UIColor.redColor;
       testView.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"hhh.png"].CGImage);
       
       // 设置Mask
       CGSize maskSize = CGSizeMake(100, 100);
       CALayer * maskLayer = CALayer.layer;
       maskLayer.frame = CGRectMake((testView.frame.size.width - maskSize.width) / 2, (testView.frame.size.height - maskSize.height) / 2, 100, 100);
   //    maskLayer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"gift.png"].CGImage);
       maskLayer.backgroundColor = [UIColor grayColor].CGColor;
       testView.layer.mask = maskLayer;
       
       [self.view addSubview:testView];
}

- (void)testVisiual
{
    CGSize viewSize = CGSizeMake(200.0, 200.0);
       UIView * testView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - viewSize.width) / 2, (self.view.frame.size.height - viewSize.height) / 2, viewSize.width, viewSize.height)];
       
       // 设置内容
       testView.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"hhh.png"].CGImage);
       
       // 设置毛玻璃效果
       CGSize maskSize = CGSizeMake(100, 100);
       UIBlurEffect * blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
       UIVisualEffectView * visualView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
       visualView.frame = CGRectMake((testView.frame.size.width - maskSize.width) / 2, (testView.frame.size.height - maskSize.height) / 2, 100, 100);
       
       [testView addSubview:visualView];
       [self.view addSubview:testView];
}

- (void)testBezierPath
{
    UIView *view2 = [[UIImageView alloc]initWithFrame:CGRectMake(100,300,100,50)];
    view2.backgroundColor = [UIColor whiteColor];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:view2.bounds.size];
    CAShapeLayer *maskLayer =[[CAShapeLayer alloc]init];
    //设置大小
    maskLayer.frame = view2.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    view2.layer.mask= maskLayer;
    [self.view addSubview:view2];
}

- (void)testCoreGraphics
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100,100,100,100)];
    imageView.image= [UIImage imageNamed:@"hhh"];
    //开始对imageView进行画图
    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO,1.0);
    //使用贝塞尔曲线画出一个圆形图
    [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];
    [imageView drawRect:imageView.bounds];
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    //结束画图
    UIGraphicsEndImageContext();
    [self.view addSubview:imageView];
}

- (void)testRasterize
{
    CGSize viewSize = CGSizeMake(200.0, 200.0);
       UIView * testView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - viewSize.width) / 2, (self.view.frame.size.height - viewSize.height) / 2, viewSize.width, viewSize.height)];
       
       // 设置内容
   //    testView.backgroundColor = UIColor.redColor;
       testView.layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"hhh"].CGImage);
       testView.layer.shouldRasterize = YES;
       
       [self.view addSubview:testView];
}

- (void)testGroupopacity
{
    
       self.view.backgroundColor = UIColor.blackColor;
       
       CGSize viewSize = CGSizeMake(200.0, 200.0);
       UIView * testView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - viewSize.width) / 2, (self.view.frame.size.height - viewSize.height) / 2, viewSize.width, viewSize.height)];
       
       // 设置内容
       testView.backgroundColor = UIColor.whiteColor;
       testView.layer.allowsGroupOpacity = YES;
       testView.layer.opacity = 0.5;   //单独设置Layer的区域离屏渲染
       
       CGSize subSize = CGSizeMake(100, 100);

       // 设置子Layer
       CATextLayer * subLayer = CATextLayer.layer;
       subLayer.frame = CGRectMake((testView.frame.size.width - subSize.width) / 2, (testView.frame.size.height - subSize.height) / 2, subSize.width, subSize.height);
       subLayer.backgroundColor = [UIColor whiteColor].CGColor;
       subLayer.foregroundColor = UIColor.blackColor.CGColor;
       subLayer.string = @"Text";
     //  subLayer.opacity = 0.5;   //单独设置时子Layer的区域离屏渲染
       [testView.layer addSublayer:subLayer];
//
//       // 设置子View
//       UIView * subView = [[UIView alloc] initWithFrame:CGRectMake((testView.frame.size.width - subSize.width) / 2, (testView.frame.size.height - subSize.height) / 2, subSize.width, subSize.height)];
//       subView.backgroundColor = UIColor.whiteColor;
//       [testView addSubview:subView];
//
       [self.view addSubview:testView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
